
import {getGoodsListApi,getCarouselAllApi,getShopListApi,getSkuApi} from '@/service/index.js'

export default{
	namespaced: true,
	state:{//存放状态
		goodsList:uni.getStorageSync('goodsList')||'',
		carouseList:uni.getStorageSync('carouseList')||'',
		shopList:uni.getStorageSync('shopList')||'',
	},
	mutations:{
		// 储存商品信息
		GOOD_INFO(state,data){
			state.goodsList=data
			uni.setStorageSync('goodsList',data)
		},
		// 轮播图
		CAROUSE_INFO(state,data){
			state.carouseList=data
			uni.setStorageSync('carouseList',data)
		},
		// 所有商品列表
		SHOP_LIST(state,data){
			state.shopList=data
			uni.setStorageSync('shopList',data)
		}
	},
	actions:{
		// 获取商品分类信息
		async getGoodsList({commit},params){
			let res=await getGoodsListApi(params)
			if(res.statusCode===200){
				commit('GOOD_INFO',res.data.result)
			}
		},
		// 获取轮播图
		async getCarouselAll({commit},params){
			let res=await getCarouselAllApi(params)
			if(res.statusCode===200){
				commit('CAROUSE_INFO',res.data.result)
			}
		},
		// 获取商品列表
		async getShopList({commit},params){
			let res=await getShopListApi(params)
			if(res.statusCode===200){
				commit('SHOP_LIST',res.data.result.rows)
			}
		},
		// 获取sku
		async getSku({commit},id){
			let res=await getSkuApi(id)
			return Promise.reject(res.data.result)
		}
	},
	getters:{
		
	}
}